Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
Javacript [ document.write ("___"); ] Shortcut to not start each line with document.write (" or some alternative

In this code I want to insert some HTML and normal text in JavaScript and don't want it to always enter document.write(" in starting of each line like this:

document.write ("<Style>");
document.write ("html {height:100%}");
document.write (".header {background-color: Aliceblue}");
document.write ("</Style>");

document.write ("<Div class='header'>Website Name</div>");
document.write ("<P style='color:red'>Some text i gathered here</p>");

It'll be very helpful if someone could solve this problem or give me some alternative.😊😊😊

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. You can write all at once using ``:
document.write(`
  <style>
    html {height:100%}
    .header {background-color: Aliceblue}"
  </style>

  <div class="header">Website Name</div>
  <p style="color:red">Some text i gathered here</p>
`)
  1. You can create function for it and call it where you need it:
<script>
  function write(data) {
    document.write(data)
  }
</script>

...

<script>
  write("<style>");
  write("html {height:100%}");
  ...
</script>

Warning:

  • write tags names in lowercase:
<Style> -> wrong
<style> -> ok
  • Don't use same quotes inside and outside of string:
"<div class="header">Website Name</div>" -> err
"<div class='header'>Website Name</div>" -> ok
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda